import groovy.swing.SwingBuilder
import java.awt.BorderLayout

def expando = new groovy.util.Expando()

expando.run = {action -> 

   // a demo of a groovy's SwingBuilder feature
   def swing = new SwingBuilder()
   
  /* def count = 0
   def textlabel
   def frame =
     swing.frame(title:'Frame', size:[300,300]) {
       borderLayout()
       textlabel = label(text:"Clicked ${count} time(s).",
                         constraints: BorderLayout.NORTH)
       button(text:'Click Me',
                 actionPerformed: {count++; textlabel.text = "Clicked ${count} time(s)."},
                 constraints:BorderLayout.SOUTH)
   }
   frame.pack()
   frame.show()*/
   
   def theMap = [color: "green", object: "pencil"]
   def frame = swing.frame(title: 'A Groovy Swing', location: [240,240]){
	   panel {
		   for (entry in theMap){
			   label(text: entry.key)
			   textField(text: entry.value)
		   }
		   button (text: 'About', actionPerformed: {
			 def pane = swing.optionPane(message: 'Powerd by Groovy SwingBuilder') 
			 def dialog = pane.createDialog(null, 'About')
			 dialog.show()
		   })
	   }
   }
   frame.pack()
   frame.show()
   
}

expando.init = { window ->
  expando.workbenchWindow = window	
}

expando.selectionChanged = {action, selection ->
  expando.selection = selection
}

expando.dispose = { }

expando
